// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CharacterManager from "../Models/Characters/CharacterManager";
import EquipManager from "../Models/Equips/EquipManager";
import GateManager from "../Models/Gates/GateManager";
import LevelManager from "../Models/Levels/LevelManager";
import MapManager from "../Models/Maps/MapManager";
import PetManager from "../Models/Pets/PetManager";
import ShopManager from "../Models/Shops/ShopManager";
import SkillManager from "../Models/Skills/SkillManager";
import TaskManager from "../Models/Tasks/TaskManager";
import PlatformManager from "../Platforms/PlatformManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ConfigManager extends cc.Component {

    public signinConfig: any[] = [{ amount: 100 }, { amount: 100 }, { amount: 100 }, { amount: 100 },
    { amount: 100 }, { amount: 100 }, { amount: 500 }];

    private static _single: ConfigManager;
    public static get single(): ConfigManager {
        return ConfigManager._single;
    }

    protected onLoad(): void {
        if (ConfigManager._single == null) {
            ConfigManager._single = this;
        } else {
            this.node.destroy();
            this.node.removeFromParent();
        }

        cc.game.addPersistRootNode(this.node);


    }

    protected onEnable(): void {

        cc.resources.preloadDir("configs", cc.JsonAsset, (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
            console.log("load: " + finish + "/" + total);
        }, (error: Error, items: cc.AssetManager.RequestItem[]) => {
            this.buildModel();
            PlatformManager.single.initPlatform();
        });
        cc.resources.loadDir("configs");
    }

    buildModel() {

        CharacterManager.single.initConfig();
        GateManager.single.initConfig();
        LevelManager.single.initConfig();
        SkillManager.single.initConfig();
        EquipManager.single.initConfig();
        PetManager.single.initConfig();
        ShopManager.single.initConfig();
        MapManager.single.initConfig();
        TaskManager.single.initConfig();
    }

}

